import http from '../../../common/httpUtil';
import * as types from './historyMutationTypes';

const actions = {
  queryHistory({commit}, {pageIndex = 1, pageSize = 10, combinationCode} = {}) {
    commit(types.SYS_FILE_UPLOAD_QUERY_FILES_BEGIN);

    return http.get(`portfolio/query/history_code?page=${pageIndex}&size=${pageSize}&combinationCode=${combinationCode}`)
      .then(data => {
        console.log(data)
        var files = data.content
        console.log(files)
        commit(types.SYS_FILE_UPLOAD_QUERY_FILES_SUC, {files});
      });
  },
  queryHistoryCount({commit}, {pageIndex = 1, pageSize = 10, combinationCode}) {
    commit(types.SYS_FILE_UPLOAD_QUERY_FILES_COUNT_BEGIN);

    return http.get(`portfolio/query/history_code?pageIndex=${pageIndex}&pageSize=${pageSize}&combinationCode=${combinationCode}`).then(data => {
      var totalCount = data.totalElements
      console.log(totalCount)
      commit(types.SYS_FILE_UPLOAD_QUERY_FILES_COUNT_SUC, {totalCount})
    });
  },
  editHistory({commit}, {combinationId, accumulatedIncome}) {
    return http.get(`portfolio/query/update_id?combinationId=${combinationId}&accumulatedIncome=${accumulatedIncome}`).then(data => {
      console.log(data)
      commit(types.SYS_FILE_UPDATE_HISTORY, {combinationId, accumulatedIncome})
    });
  },
  addHistory({commit}, {combinationCode, accumulatedIncome, tradeDate}) {
    return http.post(`portfolio/query/add_his?combinationCode=${combinationCode}&accumulatedIncome=${accumulatedIncome}&tradeDate=${tradeDate}`).then(data => {
      console.log(data)
      var file = {
        combinationCode: combinationCode,
        accumulatedIncome: accumulatedIncome,
        tradeDate: tradeDate
      }
      commit(types.SYS_FILE_UPLOAD_SAVE_FILE_SUC, {file})
      return data
    });
  },
  delHistory({commit}, {combinationId}) {
    return http.get(`portfolio/query/delete_history?combinationId=${combinationId}`).then(data => {
      console.log(data)
      commit(types.SYS_FILE_DEL_HISTORY, {combinationId})
    });
  }
};


export default actions;
